<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.prime.com.tr/ui"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html">

    <body>

        <ui:composition template="../templates/default3.xhtml">         

            <ui:define name="content">
                <h:form id="addPurchaseOrder" binding="#{purchaseOrderManagerBean.loadAddPurchaseOrder}">
                    <p:panel header="Customer information" id="addPurchaseOrder1">
                        <font class="fieldNote">* - Mandatory Field<br/></font> 
                        <p:messages id="error"/>
                        <table>
                            <tr>
                                <td width ="180px">Company:</td>
                                <td width="200px"> <b><h:outputText id ="company" value="#{purchaseOrderManagerBean.customer.company}"  />  </b>
                                </td>
                                <td></td><td></td>
                            </tr>
                            <tr>
                                <td>Company Address:</td>
                                <td><h:outputText id ="address" value="#{purchaseOrderManagerBean.companyAddress.street}, 
                                                  #{purchaseOrderManagerBean.companyAddress.country}, #{purchaseOrderManagerBean.companyAddress.postal}             " /> </td>

                                <td></td><td></td>
                            </tr>
                            <tr>
                                <td>Purchase Order No.:</td>
                                <td><p:inputText label="Purchase Order No." id="poNumber" required="true" requiredMessage="Purchase Order No. Required" value="#{purchaseOrderManagerBean.poNumber}" />
                                    <font class="fieldNote">*</font>
                                </td>
                               <td>Quotation No.:</td>
                                <td><p:autoComplete required ="true" requiredMessage ="Quotation No. Required" id="qNumber" value="#{purchaseOrderManagerBean.quotationNumber}" forceSelection="true" completeMethod="#{purchaseOrderManagerBean.complete}">
                                    </p:autoComplete>  

                                    <font class="fieldNote">*</font></td>
                            </tr>
                          
                            <tr>
                                <td>Purchase Order Date:</td>
                                <td><p:calendar required="true" requiredMessage="Purchase Order Date Required" value="#{purchaseOrderManagerBean.poDate}"  />  
                                    <font class="fieldNote">*</font>
                                </td>
                             <td></td><td></td>
                            </tr>
                             <tr>
                                <td>Remark:</td>
                                <td><p:inputText id="remark" value="#{purchaseOrderManagerBean.remark}" />  

                                </td> 
                                
                            </tr>
                        </table>

                    </p:panel>

                    <p:panel header="Select Billing address" id="addPurchaseOrder3">


                        <p:dataTable id="AddressB" var="address" value="#{purchaseOrderManagerBean.billingAddresses}" paginator="false"                                     
                                     selectionMode="single" selection="#{purchaseOrderManagerBean.billingAddress}" emptyMessage="No address found with given criteria.">     


                            <p:column headerText="Street"> 
                                <h:outputText value="#{address.street}" />                                             
                            </p:column> 
                            <p:column headerText="Postal Code"> 
                                <h:outputText value="#{address.postal}" />                                             
                            </p:column> 
                            <p:column headerText="City"> 
                                <h:outputText value="#{address.city}" />                                             
                            </p:column> 
                            <p:column headerText="Country"> 
                                <h:outputText value="#{address.country}" />                                             
                            </p:column> 

                        </p:dataTable>                  

                    </p:panel>
                    <p:panel header="Order items" id="addPurchaseOrder4">
                        <p:dataTable id="POItems" var="purchaseItem" value="#{purchaseOrderManagerBean.purchaseItems}" paginator="false"                                     
                                     emptyMessage="No item found with given criteria.">                                                             

                            <p:column headerText="Product name"> 
                                <h:outputText value="#{purchaseItem.product.name}" />                                             
                            </p:column> 
                            <p:column headerText="Quantity"> 
                                <h:outputText value="#{purchaseItem.quantity}" />                                             
                            </p:column> 
                            <p:column headerText="Unit price"> 
                                <h:outputText value="#{purchaseItem.unitPrice}">
                                    <f:convertNumber type="currency"/>
                                </h:outputText>
                            </p:column>      
                            <p:column headerText="Shipping rate (case)"> 
                                <h:outputText value="#{purchaseItem.shippingRate}">
                                    <f:convertNumber type="currency"/>
                                </h:outputText>
                            </p:column>      
                            <p:column headerText="Discount"> 
                                <h:outputText value="#{purchaseItem.discount}" />                                             
                            </p:column> 
                            <p:column headerText="Sub Total"> 
                                <h:outputText value="#{purchaseItem.subTotal}">
                                    <f:convertNumber type="currency"/>
                                </h:outputText>
                            </p:column>  
                        </p:dataTable> 
                        <p:commandButton id="btnAddItem" value="Add item" actionListener="#{purchaseOrderManagerBean.addPurchaseItem}" update="addPurchaseOrder" ajax="true" />                                                               
                 </p:panel>
                    

                    <br/>                    <br/>




                    <table class="panel">
                        <tr aligh ="right">
                            <td width ="170">Sub-total:</td>
                            <td>
                                <h:outputText value="#{purchaseOrderManagerBean.cost}">
                                    <f:convertNumber type="currency"/>
                                </h:outputText>
                            </td>      
                        </tr>
                        <tr aligh ="right">
                            <td width ="170">Shipping cost:</td>
                            <td>
                                <h:outputText value="#{purchaseOrderManagerBean.shippingCost}">
                                    <f:convertNumber type="currency"/>
                                </h:outputText>
                            </td>      
                        </tr>
                        <tr aligh ="right">
                            <td width ="170">Total:</td>
                            <td><b>
                                    <h:outputText value="#{purchaseOrderManagerBean.totalAmount}">  
                                        <f:convertNumber type="currency"/>
                                    </h:outputText>
                                </b>
                            </td>      
                        </tr>
                        <tr aligh ="right">
                            <td>Credit Request (%):</td>
                            <td><h:inputText value="#{purchaseOrderManagerBean.creditRate}" />  </td>
                        </tr>

                        <tr>
                            <td colspan="2" class="btn"><hr/>
                            <p:commandButton id="btnAddPO" value="Create PO" actionListener="#{purchaseOrderManagerBean.addPurchaseOrder}" update="error" ajax="true" /></td>
                        </tr>
                    </table>


                </h:form>
            </ui:define>        

        </ui:composition>

    </body>

</html>
